package com.example.finalsystem.Controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.example.finalsystem.Service.GoodsService;
import com.example.finalsystem.Service.OutListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OutController {
    @Autowired
    OutListService outListService;
    @Autowired
    GoodsService goodsService;
//    传来 要出货的商品名称 和  数量
    @ResponseBody
    @PostMapping("/out/canOut")
    public String canOut(@RequestParam String name,@RequestParam Integer number)
    {
       return goodsService.canOut(name,number);
    }

    //    仓库管理员 确认 出货单 state 设置为已分发， logisticsInformation 填写的物流信息
//    销售管理员 更改出货单  state 不变，logisticsInformation  为空字符串（销售管理员不能填写物流信息）， 可以修改出货数量
    @ResponseBody
    @PostMapping("/out/fixOutList")
    public String fixOutList(@RequestParam String outListId,@RequestParam Integer exportNumber,@RequestParam String logisticsInformation,@RequestParam String state)
    {
        return outListService.fixOutList(outListId,exportNumber,logisticsInformation,state);
    }


    @ResponseBody
    @PostMapping("/out/deleteOutList")
    public String deleteOutList(@RequestParam String outListId)
    {
        return outListService.deleteOutList(outListId);
    }

    @ResponseBody
    @PostMapping("/out/getOutList")
    public String getOutList(@RequestParam String outListId)
    {
        return JSON.toJSONString( outListService.getOutList(outListId) );
    }

    @ResponseBody
    @PostMapping("/out/getOutListByListGoodsId")
    public String getOutListByListGoodsId(@RequestParam Long listGoodsId)
    {
        return JSONArray.toJSONString(outListService.getAllOutListByListGoodsId(listGoodsId));
    }

    @ResponseBody
    @PostMapping("/out/getAllOutList")
    public String getAllOutList()
    {
        return JSONArray.toJSONString(outListService.getAllOutList());
    }

}
